<?php


namespace App\Http\Controllers\Internal;


use App\Models\Knowledge;

class KnowledgeController extends Controller
{
    public function index()
    {
        $this->validate($this->request, [
            'knowledgeIds' => 'required|array'
        ]);
        $knowledgeIds = $this->request->input('knowledgeIds');
        $knowledgeObj = Knowledge::whereIn('id', $knowledgeIds)->get();
        $items = [];
        /** @var Knowledge $itemObj */
        foreach ($knowledgeObj as $itemObj) {
            $items[] = [
                'id' => $itemObj->getId(),
                'en' => $itemObj->getName(),
                'cn' => $itemObj->getChinese(),
                'audio' => $itemObj->audio()->value('uri'),
                'cover' => $itemObj->getCover(),
            ];
        }
        return $this->sendSuccessJson($items);

    }
}